/******************************************************************************
---这里编写了基本功能函数---
	1 蓝牙的初始化配置
	2 按键键值的读取
************************************************************************************************/
#include "MyBlue.h"

/**----------------------------------------------------------------------------------------------
* @brief	串口初始化
* @param	无
* @retval	无
---------------------------------------------------------------------------------*/
void UART_config(void)
{
	COMx_InitDefine		COMx_InitStructure;					//½á¹¹¶¨Òå
	COMx_InitStructure.UART_Mode      = UART_8bit_BRTx;	//Ä£Ê½, UART_ShiftRight,UART_8bit_BRTx,UART_9bit,UART_9bit_BRTx
	COMx_InitStructure.UART_BRT_Use   = BRT_Timer1;			//Ñ¡Ôñ²¨ÌØÂÊ·¢ÉúÆ÷, BRT_Timer1, BRT_Timer2 (×¢Òâ: ´®¿Ú2¹Ì¶¨Ê¹ÓÃBRT_Timer2)
	COMx_InitStructure.UART_BaudRate  = 115200ul;			//²¨ÌØÂÊ, Ò»°ã 110 ~ 115200
	COMx_InitStructure.UART_RxEnable  = ENABLE;				//½ÓÊÕÔÊÐí,   ENABLE»òDISABLE
	COMx_InitStructure.BaudRateDouble = DISABLE;			//²¨ÌØÂÊ¼Ó±¶, ENABLE»òDISABLE
	COMx_InitStructure.UART_Interrupt = ENABLE;				//ÖÐ¶ÏÔÊÐí,   ENABLE»òDISABLE
	COMx_InitStructure.UART_Priority    = Priority_0;			//Ö¸¶¨ÖÐ¶ÏÓÅÏÈ¼¶(µÍµ½¸ß) Priority_0,Priority_1,Priority_2,Priority_3
	COMx_InitStructure.UART_P_SW      = UART1_SW_P30_P31;	//ÇÐ»»¶Ë¿Ú,   UART1_SW_P30_P31,UART1_SW_P36_P37,UART1_SW_P16_P17,UART1_SW_P43_P44
	UART_Configuration(UART1, &COMx_InitStructure);		//³õÊ¼»¯´®¿Ú1 UART1,UART2,UART3,UART4
	EA=1;//中断总开关
	
	PrintString1("STC8H8K64U UART1 Test Programme!\r\n");	//UART1·¢ËÍÒ»¸ö×Ö·û´®
}

/*********************************************************************************************************
* @brief	按键键值读取函数
* @param	无
* @retval	KeyNum（unsigned char）
************************************************************************************************** */
unsigned char Key_Jian(void)
{
	unsigned char KeyNum = 0;
	if(P32==1){delay_ms(5);if(P36==0);delay_ms(5);KeyNum=1;}
	if(P33==1){delay_ms(5);if(P36==0);delay_ms(5);KeyNum=2;}
	if(P34==1){delay_ms(5);if(P36==0);delay_ms(5);KeyNum=3;}
	return KeyNum;
}

